package graphicEval;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JPanel;

public class PointCreate extends JPanel {

	private Readr r;
	private ArrayList<ArrayList<Punkt>> aLList;

	public PointCreate() {
		this.aLList = new ArrayList<ArrayList<Punkt>>();
		this.setBackground(Color.WHITE);
		this.setPreferredSize(new Dimension(800, 600));
		r = new Readr("filename.txt");
		lex();

	}

	/**
	 * Ruft Lexer aus dem Reader auf. Die Datei wird ausgelesen und an die allist gebunden.
	 */
	private void lex() {
		try {
			aLList = r.lexer(r.readAll());
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * Zeichnen
	 */
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		Font f = new Font("Verdana", Font.PLAIN, 9);
		g.setFont(f);
		g.setColor(Color.gray);
		paintXY(g);
		
		g.setColor(Color.BLACK);
		paintGraph(g);

	}

	private void paintGraph(Graphics g) {
		for (ArrayList<Punkt> a : aLList) {
			g.drawString(a.get(0).getNodes() + " NODES", 650, 550);
			for (Punkt p : a) {
				g.drawString("#", (int) p.getX() * 5, (int) p.getY() * 5);
			}

		}

	}


	/**
	 * Das Setup des Grids
	 * @param g
	 */
	private void paintXY(Graphics g) {

		g.drawString("crossings", 35, 570);
		g.drawString("turns", 750, 50);

		g.drawRoundRect(600, 500, 200, 100, 5, 5);
		g.drawString("#Node Histrogram", 600, 500);

		// X GRID
		for (int i = 0; i < 600; i++) {
			g.drawLine(i * 5, 0, i * 5, 5);
			g.drawString(5 * i + "", i * 25, 20);
		}
		// Y GRID

		for (int i = 0; i < 300; i++) {
			g.drawLine(0, i * 5, 5, i * 5);
			g.drawString( 5* i + "", 5, i * 25);
		}
	}


}
